package com.dkm.orproject.dkmoa.service.serviceimpl;

import com.dkm.orproject.dkmoa.dao.OaOrganizationMapper;
import com.dkm.orproject.dkmoa.dao.OaRolePersonnelMapper;
import com.dkm.orproject.dkmoa.domain.OaOrganization;
import com.dkm.orproject.dkmoa.domain.vo.OaOrganizationVo;
import com.dkm.orproject.dkmoa.service.OaOrganizationService;
import com.dkm.orproject.utils.utils.IdToobtainUtils;
import com.dkm.orproject.utils.utils.Tools;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 *  @ClassName : OaOrganizationServiceImpl  //类名
 *  @Description :   //描述
 *  @Author : 石智诚  //作者
 *  @Date: 2020-08-05 10:56  //时间
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class OaOrganizationServiceImpl implements OaOrganizationService {

    @Resource
    OaOrganizationMapper mapper;
    @Resource
    OaRolePersonnelMapper rolePersonnelMapper;
    @Resource
    IdToobtainUtils utils;


    @Override
    public int insert(OaOrganization record) {
        record.setOrganizationCode(Tools.clientIdentity(String.valueOf(mapper.count()),"OR",4));
        /* 如果角色id 不为空*/
        return mapper.insertSelective(record);
    }
    @Override
    public int delete(Long pkPostId) {
        return mapper.deleteByPrimaryKey(pkPostId);
    }

    @Override
    public List<OaOrganization> findByAll() {
        return mapper.findByAll();
    }

    @Override
    public int findByKeyWord(String keyword) {
        return mapper.findByKeyword(keyword);
    }

    @Override
    public List<OaOrganization> findById(Long pkPostId) {
        return mapper.findById(pkPostId);
    }

    @Override
    public OaOrganization selectByPostId(Long pkPostId) {
        return mapper.selectByPrimaryKey(pkPostId);
    }

    @Override
    public OaOrganizationVo selectByPkPostId(Long pkPostId) {
        return mapper.selectByPkPostId(pkPostId);
    }

    @Override
    public int update(OaOrganization record,String personnelName) {
        rolePersonnelMapper.deleteById(record.getPkPostId());
        record.setUpdatedBy(personnelName);
        record.setUpdatedTime(new Date());
        return mapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateById(Long pkDepartmentId,String personnelName) {
        return mapper.updateById(pkDepartmentId,personnelName, new Date());
    }

    @Override
    public int deleteAll(List<Long> list) {
        return mapper.deleteAll(list);
    }

    @Override
    public int updateAll(List<Long> list,String personnelName) {
        return mapper.updateAll(list,personnelName, new Date());
    }

    @Override
    public Long rowCount(OaOrganizationVo organization, String startTime, String endTime) {
        return mapper.rowCount(organization,startTime,endTime);
    }

    @Override
    public List<OaOrganizationVo> findAll(OaOrganizationVo organization, Integer page, Integer limit, String startTime, String endTime) {
        PageHelper.startPage(page,limit);
        return mapper.findAll(organization,startTime,endTime);
    }


}
